package com.huijie.core.util;


import java.util.concurrent.*;

import static java.util.concurrent.Executors.newFixedThreadPool;

/** 
* @ClassName: ThreadPool
* @Description: 单例线程池
* @author JsonY
* @date 2017年12月4日 下午2:21:27
*/
public class ThreadPool {

    //线程缓冲队列
    private static BlockingQueue<Runnable> bqueue = new ArrayBlockingQueue<Runnable>(500);
    // 核心线程数，会一直存活，即使没有任务，线程池也会维护线程的最少数量
    private static final int SIZE_CORE_POOL = 20;
    // 线程池维护线程的最大数量
    private static final int SIZE_MAX_POOL = 50;
    // 线程池维护线程所允许的空闲时间
    private static final long ALIVE_TIME = 2000;


    private static ThreadPoolExecutor pool = new ThreadPoolExecutor(SIZE_CORE_POOL, SIZE_MAX_POOL, ALIVE_TIME, TimeUnit.MILLISECONDS, bqueue, new ThreadPoolExecutor.CallerRunsPolicy());
    
    private static ExecutorService poolCallService= newFixedThreadPool(10);

    static {

        pool.prestartAllCoreThreads();
    }


    public static ThreadPoolExecutor getPool() {
        return pool;
    }
    
    public static ExecutorService getPoolCallService() {
        return poolCallService;
    }

//    public static void main(String[] args) {
//        System.out.println(pool.getPoolSize());
//    }


}
